package team.knowers.qzh.qzhgrame.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import team.knowers.qzh.qzhgrame.common.convention.result.Result;
import team.knowers.qzh.qzhgrame.common.convention.result.Results;
import team.knowers.qzh.qzhgrame.dto.req.AddChapterReqDTO;
import team.knowers.qzh.qzhgrame.dto.req.DeleteChapterReqDTO;
import team.knowers.qzh.qzhgrame.dto.req.UpdateChapterReqDTO;
import team.knowers.qzh.qzhgrame.dto.resp.AllChapterRespDTO;
import team.knowers.qzh.qzhgrame.service.ChapterGrameService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class ChapterGrameController {
    private final ChapterGrameService chapterGrameService;

    /**
     * 创建单元
     * @param req
     * @return
     */
    @PostMapping("/api/qzh-server/admin/v1/chapter/add")
    public Result<Integer> addChapter(@RequestBody AddChapterReqDTO req)
    {
        return Results.success(chapterGrameService.addChapter(req));
    }
    /**
     * 删除单元
     */
    @PutMapping("/api/qzh-server/admin/v1/chapter/delete/{id}")
    public Result<Integer> deleteChapter(@PathVariable("id") Long id)
    {
        return Results.success(chapterGrameService.deleteChapter(id));
    }
    /**
     * 修改单元
     */
    @PutMapping("/api/qzh-server/admin/v1/chapter/update")
    public Result<Integer>  updateChapter(@RequestBody UpdateChapterReqDTO req)
    {
        return Results.success(chapterGrameService.updateChapter(req));
    }

    /**
     * 展示该课程的所有单元
     * @param id
     * @return
     */
    @GetMapping("/api/qzh-server/admin/v1/chapter/show/{id}")
    public Result<List<AllChapterRespDTO>>showAllChapter(@PathVariable("id") Long id)
    {
        return Results.success(chapterGrameService.showAllChapter(id));
    }
}
